package com.zhc.tools.common.util;


import java.lang.reflect.InvocationTargetException;
import java.math.BigDecimal;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.ConvertUtils;
import org.apache.commons.beanutils.converters.BigDecimalConverter;

/**
 * 对象复制工具类
 * 	增加 Date、BigDecimal 属性复制
 * @author zhc
 */
public class BeanUtilsEx extends BeanUtils {
	
	private static final BigDecimal BIGDECIMAL_ZERO = new BigDecimal("0"); 
  
    static {  
            //注册util.date的转换器，即允许BeanUtils.copyProperties时的源目标的util类型的值允许为空  
            ConvertUtils.register(new DateConvert(), java.util.Date.class);  
            ConvertUtils.register(new DateConvert(), String.class);  
//          BeanUtilsBean beanUtils = new BeanUtilsBean(ConvertUtils.class,new PropertyUtilsBean());  
            BigDecimalConverter bd = new BigDecimalConverter(BIGDECIMAL_ZERO);
            ConvertUtils.register(bd, BigDecimal.class);
    }  
  
  
    public static void copyProperties(Object target, Object source) throws  
              InvocationTargetException, IllegalAccessException {  
         //支持对日期copy  
         org.apache.commons.beanutils.BeanUtils.copyProperties(target, source);  
    }  
}  